package com.banshuibao.bsb_android.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.banshuibao.bsb_android.Constants;
import com.banshuibao.bsb_android.R;
import com.banshuibao.bsb_android.util.GetLoginInfo;
import com.banshuibao.bsb_android.util.IntentManager;
import com.banshuibao.bsb_android.util.ShareUtil;

public class InviteMembersActivity extends BaseActivity implements View.OnClickListener {

    private RelativeLayout code, invite;
    private GetLoginInfo getLoginInfo;
    private TextView menu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_invite_members);
        getLoginInfo = GetLoginInfo.getLoginInfoInstance(this).readUser();
        initView();
    }

    public void initView() {
        setTitleText("邀请会员");
        code = findViewById(R.id.inviting_code);
        invite = findViewById(R.id.inviting_invite);
        menu = findViewById(R.id.menu);
        menu.setVisibility(View.VISIBLE);
        menu.setText("邀请记录");
        menu.setOnClickListener(this);
        code.setOnClickListener(this);
        invite.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.inviting_code:
                String cookieId = getLoginInfo.getCookieId();
                if(!TextUtils.isEmpty(cookieId)){
                    IntentManager.goInviteCodeActivity(this);
                }else{
                    IntentManager.goLoginActivity(this);
                }

                break;

            case R.id.inviting_invite:
                String firmId = getLoginInfo.getFirmId();
                String url = "?firmId="+firmId+"&inviteUserId="+getLoginInfo.getUserId()+"&firmName="+getLoginInfo.getFirmName()+"&inviteUserName="+getLoginInfo.getName();
                if(!TextUtils.isEmpty(firmId)){
                    ShareUtil.showShare(this, Constants.Url.INVITE_MEMBERS+url,getLoginInfo.getName()+"邀请您加入【"+getLoginInfo.getFirmName()+"办税宝在线平台】",Constants.Url.INVITE_TEXT_SHOW,null);
                }else{
                    IntentManager.goLoginActivity(this);
                }
                break;
            case R.id.menu:
                IntentManager.goInviteRecordActivity(this);
                break;
        }
    }
}
